<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Facility extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('hotel_facility_model');
	}
 
	/*
		Display hotel list
	*/	
	public function index(){    
		 $data['page_html_title']     	  = "Facility List";
		 $data['main_content']   	  = 'facility/list';
		 $data['hotel_facility_list'] = $this->hotel_facility_model->load_facility_list();
		 
		 $this->load->view('admin_layout',$data);
	}
	
	
	/*
		load a hotel to edit
	*/
	public function edit($facility_id=0){ 
		 $data['page_html_title']   	= "Facility Edit";
		 $data['main_content'] 			= 'facility/edit';
		 $data['selected_facility_id']	= $facility_id;
		 if($facility_id>0){
			$data['facility_data']		= $this->hotel_facility_model->load_facility_detail($facility_id);
		 } 
		 $this->load->view('admin_layout',$data);
	}
		
	/*
		save a hotel
	*/	
	public function save(){    
		$this->load->library('form_validation');
		$this->form_validation->set_rules('name', 'Facility Name', 'trim|required');
		$this->form_validation->set_rules('description', 'Description', 'trim|required'); 
		
		if($this->form_validation->run()== FALSE){
			$data['page_html_title']      = "Facility Save Error"; 
			$facility_id 			 	  = ($_POST['facility_id']!=''?$_POST['facility_id']:0); 
			$data['selected_facility_id'] = $facility_id; 
		}else{ 
			$result=$this->hotel_facility_model->save();
			$data['page_html_title'] = "Facility Edit";   
			$data['message_id']		 =  $result[1];
			$facility_id			 =  $result[0]; 
		} 
		if($facility_id>0){
			$data['facility_data'] = $this->hotel_facility_model->load_facility_detail($facility_id);
		}
		$data['main_content'] 		  = 'facility/edit'; 
		$data['selected_facility_id'] = $facility_id;
		$this->load->view('admin_layout',$data);
	}	

 	/*
		delete a specified facility
	*/
	public function delete($facility_id=0){  
		 $data['message_id']   = $this->hotel_facility_model->delete_facility($facility_id);
		 $this->index();	
	}
	
}
?>